package com.example.zx.theline.zsjh.pub;

import android.content.Intent;
import android.os.Bundle;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.zx.theline.R;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import java.util.HashMap;
import java.util.Map;

import GsonBean.ShyjhxqBean;
import GsonBean.ZsyjhxxBean;
import GsonBean.ZszjhxxBean;
import Utils.MyToast;
import app.MyApplication;
import base.BaseActivity;
import network.NetWorkApi;
import network.ObjectHttpResponseHandler;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Ren on 2017/8/14.
 * 正式周计划查看
 */

public class ZszjhChaKanActivity extends BaseActivity implements View.OnClickListener {


    public static ZszjhxxBean ZszjhxxBean;
    private ShyjhxqBean mZsyjhxxBean;

    /**
     * 标题
     */
    TextView centerTextView;
    /**
     * 计划内容
     */
    TextView lb;
    TextView rjhh;
    TextView ydbh;
    TextView zfw;
    TextView rqsj;
    TextView kssj;
    TextView jssj;
    TextView xm;
    TextView dd;
    TextView hb;
    TextView lc;
    TextView xmmc;
    TextView sgnr;
    TextView sgjx;
    TextView blfh;
    TextView aqfx;
    TextView fxcs;

    /**
     * 相关单位
     */
    TextView sgdw;
    TextView sgdwfzr;
    TextView jldw;
    TextView jldwfzr;
    TextView jsdw;
    TextView jsdwfzr;
    TextView cwzd;
    TextView ddt;
    TextView dxjz;
    TextView sbgldw;
    TextView qtdw;
    TextView shcs;
    TextView xmzgbm;

    /**
     * 按钮
     */
    TextView cancel;
    TextView ckyjh;
    TextView leftTextView;
    private LinearLayout blfh_layout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zszjh_chakan);
        InitView();
        InitData();
        InitListen();
    }

    @Override
    protected void InitView() {
        centerTextView = (TextView) findViewById(R.id.centerTextView);
        centerTextView.setText("周计划详情");

        lb = (TextView) findViewById(R.id.lb);
        rjhh = (TextView) findViewById(R.id.rjhh);
        ydbh = (TextView) findViewById(R.id.ydbh);
        zfw = (TextView) findViewById(R.id.zfw);
        rqsj = (TextView) findViewById(R.id.rqsj);
        kssj = (TextView) findViewById(R.id.kssj);
        jssj = (TextView) findViewById(R.id.jssj);
        xm = (TextView) findViewById(R.id.xm);
        dd = (TextView) findViewById(R.id.dd);
        hb = (TextView) findViewById(R.id.hb);
        lc = (TextView) findViewById(R.id.lc);
        xmmc = (TextView) findViewById(R.id.xmmc);
        sgnr = (TextView) findViewById(R.id.sgnr);
        sgjx = (TextView) findViewById(R.id.sgjx);
        blfh = (TextView) findViewById(R.id.blfh);
        blfh_layout = (LinearLayout) findViewById(R.id.blfh_layout);

        aqfx = (TextView) findViewById(R.id.aqfx);
        fxcs = (TextView) findViewById(R.id.fxcs);

        sgdw = (TextView) findViewById(R.id.sgdw);
        sgdwfzr = (TextView) findViewById(R.id.sgdwfzr);
        jldw = (TextView) findViewById(R.id.jldw);
        jldwfzr = (TextView) findViewById(R.id.jldwfzr);
        jsdw = (TextView) findViewById(R.id.jsdw);
        jsdwfzr = (TextView) findViewById(R.id.jsdwfzr);
        cwzd = (TextView) findViewById(R.id.cwzd);
        ddt = (TextView) findViewById(R.id.ddt);
        dxjz = (TextView) findViewById(R.id.dxjz);
        sbgldw = (TextView) findViewById(R.id.sbgldw);
        qtdw = (TextView) findViewById(R.id.qtdw);
        shcs = (TextView) findViewById(R.id.shcs);
        xmzgbm = (TextView) findViewById(R.id.xmzgbm);

        cancel = (TextView) findViewById(R.id.cancel);
        ckyjh = (TextView) findViewById(R.id.ckyjh);
        leftTextView = (TextView) findViewById(R.id.leftTextView);
    }

    @Override
    protected void InitData() {
        if (ZszjhxxBean == null) {
            MyApplication.ShowWaitDialog(this);
            MyApplication.setWaitDialogMsg("数据错误");
        } else {
            lb.setText(ZszjhxxBean.getInfo().getLb());
            rjhh.setText(ZszjhxxBean.getInfo().getBh());
            ydbh.setText(ZszjhxxBean.getInfo().getYdbh());
            zfw.setText(ZszjhxxBean.getInfo().getSgrqks() + "至" + ZszjhxxBean.getInfo().getSgrqjs());
            kssj.setText(ZszjhxxBean.getInfo().getSgrqList().get(0).getSgrqks());
            jssj.setText(ZszjhxxBean.getInfo().getSgrqList().get(0).getSgrqjs());
            xm.setText(ZszjhxxBean.getInfo().getXlxbList().get(0).getXlmc());
            dd.setText(ZszjhxxBean.getInfo().getXlxbList().get(0).getSgdd());
            hb.setText(ZszjhxxBean.getInfo().getXlxbList().get(0).getXbmc());
            lc.setText(ZszjhxxBean.getInfo().getXlxbList().get(0).getLic());
            xmmc.setText(ZszjhxxBean.getInfo().getXmmc());
            sgnr.setText(ZszjhxxBean.getInfo().getXmmc());
            sgjx.setText(ZszjhxxBean.getInfo().getJxmc());
//            blfh.setText(ZszjhxxBean.getInfo().getBlfhmc());
            if (ZszjhxxBean.getInfo().getLb().equals("C")) {
                blfh_layout.setVisibility(View.GONE);
            } else {
                blfh_layout.setVisibility(View.VISIBLE);
                blfh.setText(ZszjhxxBean.getInfo().getBlfhmc());
            }
            aqfx.setText(ZszjhxxBean.getInfo().getAqfxcsmc());
            fxcs.setText(ZszjhxxBean.getInfo().getAqfxcsmc());

            sgdw.setText(ZszjhxxBean.getInfo().getSgdw());
            sgdwfzr.setText(ZszjhxxBean.getInfo().getSgdwfzr());
            jldw.setText(ZszjhxxBean.getInfo().getJldw());
            jldwfzr.setText(ZszjhxxBean.getInfo().getJldwfzr());
            jsdw.setText(ZszjhxxBean.getInfo().getJsdw());
            jsdwfzr.setText(ZszjhxxBean.getInfo().getJsdwfzr());
            cwzd.setText(ZszjhxxBean.getInfo().getCwzd());
            ddt.setText(ZszjhxxBean.getInfo().getDdt());
            dxjz.setText(ZszjhxxBean.getInfo().getSgdxjz());
            sbgldw.setText(ZszjhxxBean.getInfo().getSbgldw());
            qtdw.setText(ZszjhxxBean.getInfo().getQtdw());
            shcs.setText(ZszjhxxBean.getInfo().getShcs());
            xmzgbm.setText(ZszjhxxBean.getInfo().getXmzgbm());
        }
    }

    @Override
    protected void InitListen() {
        cancel.setOnClickListener(this);
        ckyjh.setOnClickListener(this);
        leftTextView.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ckyjh:
                Map<String,String> map=new HashMap<>();
                map.put("bh", ZszjhxxBean.getInfo().getYdbh());
                MyApplication.ShowWaitDialog(this);
                NetWorkApi.getZsyjhXx(map, new Callback<ShyjhxqBean>() {
                            @Override
                            public void onResponse(Call<ShyjhxqBean> call, Response<ShyjhxqBean> response) {
                                try {
                                    mZsyjhxxBean = response.body();

                                    if (mZsyjhxxBean.getMsg().equals("success")) {
                                        ZsyjhChaKanActivity.ZsyjhxxBean = mZsyjhxxBean;
                                        startActivity(new Intent(ZszjhChaKanActivity.this, ZsyjhChaKanActivity.class));
                                    }

                                } catch (Exception e) {
                                    MyToast.showFail();
                                }
                                MyApplication.HideWaitDialog();
                            }

                            @Override
                            public void onFailure(Call<ShyjhxqBean> call, Throwable t) {
                                MyToast.showFail();
                            }
                        }
                );
                break;
            case R.id.cancel:
                finish();
                break;
            case R.id.leftTextView:
                finish();
                break;
        }
    }
}
